package com.dengqi.mymodule.activity.network.module;

import com.dengqi.mymodule.activity.network.base.BasePresenter;
import com.dengqi.mymodule.activity.network.util.CheckUtil;
import com.module.retrofit.bean.ResponseBean;
import com.module.retrofit.RetrofitHelper;
import com.module.retrofit.callback.BaseObserver;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;

import java.util.LinkedHashMap;
import java.util.Map;


/**
 * @Author: dengqi
 * @CreateDate: 2020-10-15 19:51
 * @Description:
 */
public class CommonPresenter extends BasePresenter implements CommonContract.Presenter {

    private CommonContract.Model model;

    public CommonPresenter(RxAppCompatActivity activity){
        super(activity);
        this.model = RetrofitHelper.getApiService(CommonContract.Model.class);
    }

    @Override
    public void sendCaptcha(CommonContract.SmsView view) {
        String phone = view.getPhone();
        if(!CheckUtil.checkPhone(phone)){
            return;
        }
        Map<String, String> parmas = new LinkedHashMap<>();
        parmas.put("phone", phone);
        execute(model.sendCaptcha(parmas))
                .subscribe(new BaseObserver<ResponseBean<Map<String, String>>>(activity) {
                    @Override
                    public void onSuccess(ResponseBean<Map<String, String>> result) {
                        view.onSendCaptcha();

                    }

                });
    }
}
